//    Copyright (C) Kherty.  All rights reserved.
using OpenLS.Core.Serialization;

namespace OpenLS.Chart
{
    public class RadarSeries : Series, IMarkerOwner, IDataPointOwner, IDataLabelsOwner
    {
        private DataSource cat;
        private DataLabels dlbls;
        private readonly DataPoints dPt = new DataPoints();
        private Marker _marker;
        private NumericDataSource values;

        
        public Marker Marker
        {
            get { return _marker; }
            set { _marker = value; notifyPropertyChanged("Marker");}
        }

        public DataSource Categories
        {
            get { return cat; }
            set { cat = value; notifyPropertyChanged("Categories");}
        }

        public NumericDataSource Values
        {
            get { return values; }
            set { values = value; notifyPropertyChanged("Values"); }
        }


        public DataPoints DataPoints
        {
            get { return dPt; }
        }

        public DataLabels DataLabels
        {
            get { return dlbls; }
            set { dlbls = value; notifyPropertyChanged("DataLabels");}
        }

        internal override void ReadXmlCore(ReadContext context)
        {
            using (var c = context.Read("ser"))
            {
                ReadXmlBase(c);
                Marker = c.ReadOptionalElement<Marker>("marker");
                DataPoints.Clear();
                while (c.ReaderLocalName == "dPt")
                {
                    DataPoints.Add(c.ReadElement<DataPoint>());
                }
                c.WarnIf("dPt");
                DataLabels = c.ReadOptionalElement<DataLabels>(DataLabels.xmlName);
                Categories = DataSource.ReadOptionalDataSource("cat", c);
                Values = NumericDataSource.ReadOptionalNumericDataSource("val", c);
                    //\\ Values = c.ReadOptionalElementAs<INumericDataSource>("val");
                c.WarnIf("ext");
            }
        }

        internal override void WriteXmlCore(WriteContext context)
        {
            using (WriteContext c = context.Write("ser"))
            {
                WriteXmlBase(c);
                c.WriteOptionalElement(Marker);
                c.WarnIf("dPt");
                c.WriteOptionalElement(DataLabels);
                WriteOptionalNumericDataSource("cat", Categories, c);
                WriteOptionalNumericDataSource("val", Values, c); //\\ c.WriteOptionalElementAs(Values, "val");
                c.WarnIf("ext");
            }
        }
    }
}